const express = require('express')
const orderUser = express.Router()
const db = require('../../mysql/db')

async function query(account) {
    return new Promise((resolve, reject) => {
        db.query(`SELECT * FROM orders WHERE user = ?`, [account], (err, results) => {
            if (err) {
                reject(err);
            } else {
                if (results.length == 0) {
                    console.log("results.length为0");
                }
                resolve(results)
            }
        });
    })
}

orderUser.post('/orderInfo', async (req, res) => {
    try {
        const dataRes = await query(req.body.account);
        res.send({
            code: 200,
            message: '请求成功！',
            result: dataRes,
        });
    } catch (err) {
        console.error(err);
        res.status(500).send({
            code: 500,
            message: '请求失败！',
            error: err,
        });
    }
});
module.exports = orderUser
